﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq.Dynamic.Core;
using System.Threading.Tasks;
using System.Transactions;
using WMS.BasicData.Vendors;
using WMS.StorageManagement.BinLocationDefinitions;
using WMS.WarehouseManagement.PurchaseOrders;
using WMS.WarehousingManagement.NoticeOfArrivals;
using WMS.WarehousingManagement.PurchaseWarehousings.DTO;


namespace WMS.Web.Controllers.WarehousingManagement.NoticeOfArrivals
{
    /// <summary>
    /// 到货通知
    /// </summary>
    public class PurchaseWarehousingController : Controller
    {

        /// <summary>
        /// 供应商接口
        /// </summary>
        private readonly IPurchaseWarehousingAppService _purchaseWarehousingAppService;


        /// <summary>
        /// 构造函数
        /// </summary>
        public PurchaseWarehousingController(IPurchaseWarehousingAppService purchaseWarehousingAppService)
        {
            _purchaseWarehousingAppService = purchaseWarehousingAppService;
        }

        /// <summary>
        /// 视图
        /// </summary>
        /// <returns></returns>
        public IActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns></returns>
        public IActionResult Add()
        {
            return View();
        }

        /// <summary>
        /// 其他入库（分页）
        /// </summary>
        /// <param name="page">页码</param>
        /// <param name="limit">页容量</param>
        /// <returns>返回对应数据</returns>
        /// Vendor/GetVendor
        [HttpGet]
        public async Task<JsonResult> GetPurchaseWarehousing(int page, int limit)
        {
            var pagedResult = await _purchaseWarehousingAppService.GetPurchaseWarehousing(page, limit);
            return Json(new { data = pagedResult, code = 0 });
        }

        /// <summary>
        /// 获取供应商
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetVendor()
        {
            var vendorList = await _purchaseWarehousingAppService.GetVendor();
            return Json(new { data = vendorList, code = 1 });
        }

        /// <summary>
        /// 获取仓库信息
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<JsonResult> GetBinLocationDefinition()
        {
            var binLocationDefinitionListList = await _purchaseWarehousingAppService.GetBinLocationDefinition();
            return Json(new { data = binLocationDefinitionListList, code = 1 });
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <returns>返回受影响行数</returns>
        [HttpPost]
        public async Task<JsonResult> AddPurchaseWarehousing(AddDTO add)
        {
            var i = await _purchaseWarehousingAppService.AddPurchaseWarehousing(add);
            return Json(new {code = i });

        }


    }
}
